package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/02/27 22:34
 **/
public class Day2_27_Num1144 {
    class Solution {
        public int movesToMakeZigzag(int[] nums) {
            int ans = (int) 1e9, n = nums.length;
            int sum = 0;
            for(int i=1; i<n;i+=2){
                int min =  nums[i-1];
                if(i<n-1){
                    min = Math.min(min, nums[i+1]);
                }
                if(min<=nums[i]){
                    sum += nums[i]- min+1;
                }
            }
            ans = sum;
            sum = 0;
            for(int i=1;i<n;i+=2){
                if(nums[i-1]>=nums[i]){
                    sum += nums[i-1] - nums[i] + 1;
                }
                if(i<n-1 && nums[i+1] >=nums[i]){
                    sum += nums[i+1] - nums[i] + 1;
                    nums[i+1] = nums[i]-1;
                }
            }
            ans = Math.min(ans, sum);
            return ans;

        }
    }
}